<?php
echo listaUsuario();

function listaUsuario(){
	include '../../../lib/conection.php';
	include_once '../../../lib/clases.php';

	$query = "SELECT u.`id`, u.`user`, u.`email`, r.nombre FROM `usuario` u, rol r, rolxusuario x WHERE x.id_usuario=u.id AND x.id_rol = r.id";

	$resultado= mysql_query($query, $conexion) or die(mysql_error());

	$nRegistros = mysql_num_rows($resultado);

	$cadena = "";
	$tablaUsuarios = array();

	if($nRegistros > 0){
		$cadena .= "<table id='tblListaEntr' class='listado'>";
		$cadena .= "<tr><th>Apellidos</th><th>Nombre</th><th>DNI</th><th>Teléfono</th><th>Editar</th><th>Eliminar</th><tr>";
		while($r = mysql_fetch_assoc($resultado)){
			
			
			//parte de ver
			$cadena .= "<tr id='filaVerEntr".$r["id"]."'>";
			$cadena .= "<td><div id='verEntrApe".$r["id"]."'>" . $r["apellidos"] . "</div></td>";
			$cadena .= "<td><div id='verEntrNom".$r["id"]."'>" . $r["nombre"] . "</div></td>";
			$cadena .= "<td><div id='verEntrDni".$r["id"]."'>" . $r["dni"] . "</div></td>";
			$cadena .= "<td><div id='verEntrTlf".$r["id"]."'>" . $r["telefono"] . "</div></td>";
			$cadena .= "<td><a href='#' onclick='cambiaEditarEntr(".$r["id"].")'><img alt='Editar' src='images/icoEditar.png' /></a>";
			$cadena .= "<td><a href='#' onclick='popUpDelEntr(".$r["id"].")'><img alt='Eliminar' src='images/icoEliminar.png' /></a>";
			$cadena .= "</tr>";
				
			//parte de editar
			$cadena .= "<tr id='filaEditEntr".$r["id"]."' style='display: none'>";
			$cadena .= "<td><input type='text' id='editEntrApe".$r["id"]."' value='" . $r["apellidos"] . "' /></td>";
			$cadena .= "<td><input type='text' id='editEntrNom".$r["id"]."' value='" . $r["nombre"] . "'/></td>";
			$cadena .= "<td><input type='text' id='editEntrDni".$r["id"]."' value='" . $r["dni"] . "' maxlength='9' /></td>";
			$cadena .= "<td><input type='text' id='editEntrTlf".$r["id"]."' value='" . $r["telefono"] . "' maxlength='9' onkeypress='return restringirCaracteres(event,\"num\")'/></td>";
			$cadena .= "<td><a href='#' onclick='editarEntrenador(".$r["id"].")'><img alt='Editar' src='images/accept.png' /></a>";
			$cadena .= "<td><a href='#' onclick='cambiaVerEntr(".$r["id"].")'><img alt='Cancelar' src='images/cancel.png' /></a>";
			$cadena .= "</tr>";
				
		}

		$cadena .= "</table>";
		return $cadena;
	}
}